package com.neuedu.hcp.controller;


import com.neuedu.hcp.entity.NursingLevel;

import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.service.INursingLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 */

//http://127.0.0.1:8081/nursinglevel/levelList
@RestController
@RequestMapping("/nursinglevel")
public class NursingLevelController {

    @Autowired
    private INursingLevelService iNursingLevelService;

    /**
     * 分页展示数据
     * @param currentPage
     * @param size
     * @param nursingLevel
     * @return
     */
    @GetMapping("/levelList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             NursingLevel nursingLevel){
        return iNursingLevelService.getlevelListByPage(currentPage,size,nursingLevel);
    }

    /**
     * 插入
     * @param nursingLevel
     * @return
     */
    @GetMapping("/insert")
    public RespBean insert(NursingLevel nursingLevel){
        if(iNursingLevelService.insert(nursingLevel)<=0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }


    @PostMapping("/update")
    public RespBean update(@RequestBody NursingLevel nursingLevel){
        if(iNursingLevelService.updateById(nursingLevel)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除
     * @param nursingId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer nursingId){
        if(iNursingLevelService.removeById(nursingId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
